package edu.usc.cmb.iregulome.client;

import java.io.IOException;
import java.net.SocketException;
import java.util.List;
import java.util.ResourceBundle;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import edu.usc.cmb.iregulome.dao.StorageTableDAO;
import edu.usc.cmb.iregulome.entity.Sample;
import edu.usc.cmb.iregulome.job.FileDownloadJob;
import edu.usc.cmb.iregulome.thread.ThreadManager;

public class DownloadMainApp {

	public static ApplicationContext ctx;

	private static ResourceBundle bundler = ResourceBundle.getBundle("app");


	/**
	 * @param args
	 * @throws IOException
	 * @throws SocketException
	 */
	public static void main(String[] args) throws SocketException, IOException {

		ctx = new ClassPathXmlApplicationContext("context.xml");

		StorageTableDAO dao = (StorageTableDAO) ctx.getBean("storageTableDAO");

		List<Sample> samples = dao
				.retrieveDownloadSamples(Integer.parseInt(bundler
						.getString("iregulome.sample.download.number")));
		
		ThreadManager.startDatasetDownloadService();
		
		for (Sample sample : samples) {
			FileDownloadJob.putIds(sample);
		}

	}

}
